package com.lenovo.manufacture.module;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.lenovo.manufacture.R;
import com.lenovo.manufacture.net.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class module2 extends BaseActivity {

    @BindView(R.id.m2_iv1)
    ImageView m2Iv1;
    @BindView(R.id.m2_iv2)
    ImageView m2Iv2;
    @BindView(R.id.m2_ib)
    ImageButton m3Ib;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_module2);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        dialog.show();
        json.put("id", 1);
        async(data.FactoryInfo(json), v -> setView(v.getData().get(0).get("acSwitch")));
    }

    @OnClick({R.id.m2_but1, R.id.m2_but2, R.id.m2_ib})
    public void onViewClicked(View view) {
        int i;
        String s;
        switch (view.getId()) {
            case R.id.m2_but1:
                i = 1;
                s = "冷风";
                break;
            case R.id.m2_but2:
                i = 2;
                s = "暖风";
                break;
            case R.id.m2_ib:
                i = 0;
                s = "关闭";
                break;
            default:
                return;
        }
        json.put("acSwitch", i);
        async(data.setAcSwitch(json), v -> {
                    init();
                    Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
                }
        );

    }

    public void setView(String i) {
        int x, y, z;

        switch (i) {
            case "0":
                x = R.drawable.snow_close;
                y = R.drawable.warm_close;
                z = R.drawable.stat_close;
                break;
            case "1":
                x = R.drawable.snow_start;
                y = R.drawable.warm_close;
                z = R.drawable.stat_start;
                break;
            case "2":
                x = R.drawable.snow_close;
                y = R.drawable.warm_start;
                z = R.drawable.stat_start;
                break;
            default:
                return;
        }
        Glide.with(this).load(x).into(m2Iv1);
        Glide.with(this).load(y).into(m2Iv2);
        Glide.with(this).load(z).into(m3Ib);
        dialog.cancel();
    }
}
